//
//  HELCourseTypeChooseVC.m
//  sanda
//
//  Created by wsj2015 on 16/10/20.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "HELCourseTypeChooseVC.h"

@interface HELCourseTypeChooseVC ()



@end

@implementation HELCourseTypeChooseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self titleView:@"课程类型"];
    [self.view addSubview:self.tableView];
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64);
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellId"];
    [self getChooseTypeData];
    NSDictionary *dict =@{@"id":@(-1),@"typeName":@"全部"};
    [self.dataArray addObject:dict];
    
}

- (void)getChooseTypeData{
  
      weakSelf_define;
      [[HELNetworkManager sharedMg] POST:kCourseTypeList parameters:nil success:^(NSArray *responseObject) {
         
          if ([responseObject isKindOfClass:[NSArray class]]) {
              [weakSelf.dataArray addObjectsFromArray:responseObject];
          }
          [weakSelf.tableView reloadData];
      } failure:^(NSString *err) {
          alertMessage(err);
      }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    return self.dataArray.count;
//    return self.dataArray.count;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 39;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
    [cell.contentView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    
    NSDictionary *dict = self.dataArray[indexPath.row];
    UILabel *label =[UILabel new];
   
    label.textColor = [UIColor blackColor];
    label.frame  = CGRectMake((kScreenWidth -150)/2,0, 150, 39);
//    label.backgroundColor =[UIColor redColor];
    label.textAlignment= NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:16];
    [cell.contentView addSubview:label];
    label.text = dict[@"typeName"];
   
    
    return cell;
   
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.callBack) {
        self.callBack(self.dataArray[indexPath.row]);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
@end
